package chapter12;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;

import java.awt.GraphicsEnvironment;
import javax.swing.*;

public class TestPanels extends JFrame {
	
	public TestPanels(){
		JPanel p1 = new JPanel();
		p1.setLayout(new GridLayout(4, 3));
		
		for (int i = 1; i <=9; i++){
			p1.add(new JButton("" + i));
		}
		p1.add(new JButton("" + 0));
		
		JButton start = new JButton("Start");
		start.setForeground(Color.WHITE);//前景色，即字体颜色,其参数可以是Color类的实例的引用变量
		start.setBackground(Color.GREEN);//背景色，其参数可以是Color类的实例的引用变量
		p1.add(start);
		JButton stop = new JButton("Stop");
		stop.setBackground(Color.RED);
		p1.add(stop);
		
		
		JPanel p2 = new JPanel(new BorderLayout());
		p2.add(new JTextField("Time to be display here"),BorderLayout.NORTH);
		p2.add(p1,BorderLayout.CENTER);
		
		add(p2,BorderLayout.EAST);
		add(new JTextField("Food to be placed here"),BorderLayout.CENTER);
		

	}
	
	public static void getFonts(){
		/*获取系统所有支持的字体*/
		GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
		String[] fontnames = e.getAvailableFontFamilyNames();
		for(int i = 0; i < fontnames.length; i++){
			System.out.println(fontnames[i]);
		}
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		TestPanels frame = new TestPanels();
		frame.setTitle("The Front View of a Microwave Oven");
		frame.setSize(400,250);
		frame.setLocationRelativeTo(null);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
		getFonts();
	}

}
